package com.qqtech.qquan.hi.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.qqtech.core.common.util.BeanUtil;
import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.hi.model.HiRuleResult;
import com.qqtech.qquan.hi.model.HiRuleResultQuery;
import com.qqtech.qquan.hi.model.HiRuleResultVo;

@Repository
public class HiRuleResultDaoImpl extends BaseDaoImpl<HiRuleResult> implements HiRuleResultDao {
	public static final Logger log = LoggerFactory.getLogger(HiRuleResultDaoImpl.class);

	@Override
	public int updateHasFinishTask(Integer userId) {
		if (userId == null) {
			return 0;
		}
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("userId", userId);
		return sqlSessionTemplate.update(getSqlName("updateHasFinishTask"), map);
	}

	@Override
	public int queryTotalQuan(HiRuleResultQuery query) {
		Integer total=((Integer) this.sqlSessionTemplate.selectOne(getSqlName("selectTotalQuan"), BeanUtil.toMap(query)));
		return total==null?0:total;
	}

	@Override
	public int queryTotalHonor(HiRuleResultQuery query) {
		Integer total=((Integer) this.sqlSessionTemplate.selectOne(getSqlName("selectTotalHonor"), BeanUtil.toMap(query)));
		return total==null?0:total;
	}
	
	@Override
	public Page<HiRuleResultVo> queryPageList4Admin(HiRuleResultQuery query, Pageable pageable) {
		List<HiRuleResultVo> contentList = sqlSessionTemplate.selectList(getSqlName("select4Admin"), getParams(query, pageable));
		int count = sqlSessionTemplate.selectOne(getSqlName("selectCount4Admin"), BeanUtil.toMap(query));
		return new PageImpl<HiRuleResultVo>(contentList, pageable, count);
	}
	
	@Override
	public int queryCount4Admin(HiRuleResultQuery query) {
		return sqlSessionTemplate.selectOne(getSqlName("selectCount4Admin"), BeanUtil.toMap(query));
	}
	
}
